﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BoneImp;
using GLImp;
using System.Drawing;

namespace UnitTest {
	class Program {
		static Camera2D MainCamera;
		static void Main(string[] args) {
			skeleton = Skeleton.LoadFromSpine("data/spineboy.json", "data/spineboy.atlas");
			Goblin = Skeleton.LoadFromSpine("data/goblins.json", "data/goblins.atlas");
			Player = Skeleton.LoadFromSpine("data/Player/skeleton.json");
			Human = Skeleton.LoadFromSpine("data/Human/skeleton.json");

			skeleton.state.data.setMixByName("walk", "jump", 0.4f);
			skeleton.state.data.setMixByName("jump", "walk", 0.4f);

			Goblin.state.data.setMixByName("walk", "jump", 0.4f);
			Goblin.state.data.setMixByName("jump", "walk", 0.4f);

			skeleton.X = 100;
			skeleton.Y = 420;

			Goblin.X = 300;
			Goblin.Y = 430;
			Goblin.SetSkinByName("goblin");

			Player.X = 500;
			Player.Y = 430;
			Player.Root.scaleX = .5f;
			Player.Root.scaleY = .5f;

			Human.X = 500;
			Human.Y = 500;
			Human.Root.scaleX = .5f;
			Human.Root.scaleY = .5f;

			skeleton.state.setAnimationByName("walk", true);
			Goblin.state.setAnimationByName("walk", true);
			Player.state.setAnimationByName("walk", true);
			Human.state.setAnimationByName("walk", true);

			MainCamera = new Camera2D();
			MainCamera.OnRender += new GraphicsManager.Renderer(MainCamera_OnRender);
			GraphicsManager.Update += new GraphicsManager.Updater(GraphicsManager_Update);

			GraphicsManager.SetBackground(Color.Blue);
			GraphicsManager.SetResolution(800, 600);
			GraphicsManager.Start();
		}

		static void GraphicsManager_Update()
		{
			if (KeyboardManager.IsPressed(OpenTK.Input.Key.Left))
			{
				MainCamera.X -= 100;
			}

			if (KeyboardManager.IsPressed(OpenTK.Input.Key.Up))
			{
				MainCamera.Y -= 100;
			}
		}

		static Skeleton skeleton;
		static Skeleton Goblin;
		static Skeleton Player;
		static Skeleton Human;
		static void MainCamera_OnRender() {
			GraphicsManager.DrawRectangle(0, 0, 5, 5, Color.Blue);
			if (skeleton.state.animation.name == "walk") {
				if (skeleton.state.time > 2)
					skeleton.state.setAnimationByName("jump", false);
			} else {
				if (skeleton.state.time > 1)
					skeleton.state.setAnimationByName("walk", true);
			}

			skeleton.update(1 / 60f);
			skeleton.draw();

			Goblin.update(1 / 60f);
			Goblin.draw();

			Player.update(1 / 60f);
			Player.draw();

			Human.update(1 / 60f);
			Human.draw();
		}
	}
}
